<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>学校简介</title>
<link rel="stylesheet" href="/scriptZIP/layui.min.css">
	<link rel="stylesheet" href="../css/item.css">
	<link rel="stylesheet" href="../css/layui.css" />
	<style>
		#portrait {
			width: 200px;
			height: 150px;
			border: 1px solid #ddd;
		}

		.text {
			height: 200px;
			padding: 20px;
			line-height: 25px;
		}

		.offer {
			width: 90px;
			height: 35px;
			background: #1E9FFF;
			color: white;
			text-align: center;
			line-height: 35px;
			font-size: 16px;
			border-radius: 4px;
		}

		.return {
			width: 80px;
			height: 35px;
			background: #0086b6;
			color: white;
			text-align: center;
			line-height: 35px;
			margin-top: -35px;
			margin-left: 130px;
			font-size: 16px;
			border-radius: 4px;
		}

		.Form1 {
			margin-bottom: 40px;
		}

		.name,
		.brief,
		.tel,
		.fax,
		.zip,
		.address,
		.text {
			background-color: #73c7ec;
			color: white;
		}
	</style>
</head>

<body>

	<form id="form" method="post" ref="form" enctype="multipart/form-data" style="display: none">
		<input type="file" id="file" name="file" accept="image/*">
	</form>

	<div style="margin-top: 30px;" class="layui-row" id="vue-root">
		<div class="layui-col-md6 layui-col-md-offset3">
			<div class="layui-form-item">
				<label class="layui-form-label">学校名称</label>
				<div class="layui-input-block">
					<input name="schoolName" v-validate="'required'" disabled="disabled" autocomplete="off" placeholder="请输入学校名称"
						class="layui-input name" v-model="item.name">
					<div class="checkout_state" v-text="err('schoolName')"></div>
				</div>
			</div>
			<!-- <div class="layui-form-item">
				<label class="layui-form-label">图片上传</label>
				<label for="File1" id="tu1">
					<img id="portrait" :src="img">
				</label>
				<div class="checkout_state" v-text="err('file')"></div>
				<form method="post" ref="form" enctype="multipart/form-data" style="display: none">
					<input type="file" id="File1" name="file" accept="image/*" @change="upload">
				</form>
			</div> -->
			<div class="layui-form-item">
				<label class="layui-form-label">学校摘要</label>
				<div class="layui-input-block">
					<textarea name="legend" data-vv-as="学校摘要" placeholder="请输入学校摘要" class="layui-textarea brief"
						v-model="item.legend" style="resize: none;"></textarea>
					<div class="checkout_state" v-text="err('legend')"></div>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">学校电话</label>
				<div class="layui-input-block">
					<input name="contactInfo" v-validate="'required'" data-vv-as="学校电话" autocomplete="off"
						placeholder="请输入学校电话" class="layui-input tel" v-model="item.contactInfo">
					<div class="checkout_state" v-text="err('contactInfo')"></div>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">学校传真</label>
				<div class="layui-input-block">
					<input name="fax" data-vv-as="学校传真" autocomplete="off" placeholder="请输入学校传真" class="layui-input fax"
						v-model="item.fax">
					<div class="checkout_state" v-text="err('fax')"></div>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">学校邮编</label>
				<div class="layui-input-block">
					<input name="zipcode" data-vv-as="学校邮编" autocomplete="off" placeholder="请输入学校邮编"
						class="layui-input zip" v-model="item.zipcode">
					<div class="checkout_state" v-text="err('zipcode')"></div>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">学校地址</label>
				<div class="layui-input-block">
					<input name="address" v-validate="'required'" data-vv-as="学校地址" autocomplete="off"
						placeholder="请输入学校地址" class="layui-input address" v-model="item.address">
					<div class="checkout_state" v-text="err('address')"></div>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">简介</label>
				<div class="layui-input-block">
					<editor :init="init" v-model="item.summary" />
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block" style="margin-bottom: 60px;">
					<div class="offer" @click="submit">保存</div>
				</div>
			</div>
		</div>
	</div>

	<script src="/scriptZIP/qs.min.js"></script>
	<script src="/scriptZIP/vue.min.js"></script>
	
	
	<script src="/scriptZIP/axios.min.js"></script>

	<script src="/scriptZIP/tinymce.min.js"></script>
	<script src="/lib/tinymce-vue.min.js"></script>
	<script src="/js/tinymce_image_plugin.js"></script>

	<script src="/js/common.js"></script>
	<script src="/js/item.js"></script>
	<script src="/js/auth_util.js"></script>
	
	<script>
		var schoolId = top_params().id;
		var field = 'school';

		var app = new Vue(merge({
			components: {
				editor: Editor
			},
			data: {
				item: {
					pic: null
				},
				url: '/pc/school',
				init: tinymceInit
			},
			created: function () {
				var id = schoolId;
				if (!id) throw 'no school id';
				axios.get('/pc/school/' + id).then(function (res) {
					var data = res.data;
					this.item = data;
					this.copy = copy(data);
				}.bind(this));
				abled('intro',this)
			},
			methods: {
				upload: function () {
					axios.post('/pc/upload/school?schoolId=' + this.item.id,
						new FormData(this.$refs.form)).then(function (res) {
							this.item.pic = res.data.data;
						}.bind(this));
				},
				submit: function () {
					this.$validator.validate().then(function (result) {
						if (result) {
							this.fillData();
							if (this.item.id) {
								var o = compare(this.item, this.copy);
								axios.put(this.url, o).then(function () {
									alert('成功');
								});
							}
						} else {
							alert("请输入完整信息！");
						}
					}.bind(this));
				}
			},
			computed: {
				img: function () {
					if (!this.item.pic) return '../image/upload.svg';
					return '/static/' + this.item.id + '/school/' + this.item.pic;
				},
			},
			watch: {
				'item.summary': function (nv, ov) {
					replaceImg(this.item, 'summary');
				}
			}
		}));
	</script>
</body>

</html>